<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>Task Admin</title>
	<!-- 依 赖 样 式 -->
	{css href="/static/admin/component/pear/css/pear.css" /}
	{css href="/static/admin/admin/css/load.css" /}
	{css href="/static/admin/admin/css/admin.css" /}
	<!-- 主 题 更 换 -->
	<style id="pearadmin-bg-color"></style>
</head>
<!-- 结 构 代 码 -->

<body class="layui-layout-body pear-admin">
	<!-- 布 局 框 架 -->
	<div class="layui-layout layui-layout-admin">
		<div class="layui-header">
			<!-- 顶 部 左 侧 功 能 -->
			<ul class="layui-nav layui-layout-left">
				<li class="collaspe layui-nav-item"><a href="#" class="layui-icon layui-icon-shrink-right"></a></li>
				<li class="refresh layui-nav-item"><a href="#" class="layui-icon layui-icon-refresh-1" loading=600></a>
				</li>
			</ul>
			<!-- 顶 部 右 侧 菜 单 -->
			<div id="control" class="layui-layout-control"></div>
			<ul class="layui-nav layui-layout-right">
				<li class="layui-nav-item layui-hide-xs"><a href="#"
						class="fullScreen layui-icon layui-icon-screen-full"></a></li>
				<li class="layui-nav-item">
					<!-- 头 像 -->
					<a href="javascript:;">
						<img src="/static/admin/admin/images/avatar.jpg" class="layui-nav-img">
						{:getLoginUser()}
					</a>
					<!-- 功 能 菜 单 -->
					<dl class="layui-nav-child">
						<dd><a onclick="editPassword()" user-menu-title="基本资料">基本资料</a></dd>
						<dd><a href="/{:setAdminPath()}/login.html?logout=<?php echo time();?>">注销登录</a></dd>
					</dl>
				</li>
				<li class="layui-nav-item setting"><a href="#" class="layui-icon layui-icon-more-vertical"></a></li>
			</ul>
		</div>
		<!-- 侧 边 区 域 -->
		<div class="layui-side layui-bg-black">
			<!-- 顶 部 图 标 -->
			<div class="layui-logo">
				<img class="logo"></img>
				<span class="title"></span>
			</div>
			<!-- 侧 边 菜 单 -->
			<div class="layui-side-scroll">
				<div id="sideMenu"></div>
			</div>
		</div>
		<div class="layui-body">
			<div id="content"></div>
		</div>
	</div>
	<!-- 遮 盖 层 -->
	<div class="pear-cover"></div>
	<!-- 加 载 动 画-->
	<div class="loader-main">
		<div class="loader"></div>
	</div>

	<script type="text/html" id="edit-form">
		<form class="layui-form" lay-filter="info">
			<div class="mainBox">
				<div class="main-container">
					<div class="main-container">
						<input type="hidden" name="id">
						<div class="layui-form-item">
							<label class="layui-form-label">当前密码</label>
							<div class="layui-input-block">
								<input type="text" name="password_old" lay-verify="required" autocomplete="off"
									placeholder="请输入旧密码" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">新密码</label>
							<div class="layui-input-block">
								<input type="text" name="password" placeholder="请输入新密码" class="layui-input">

							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">上传密钥</label>
							<div class="layui-input-block">
								<input type="text" name="token" placeholder="请输入上传密钥" class="layui-input"
									value="{:getLoginUser('student_token')}">
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="bottom">
				<div class="button-container">
					<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit lay-filter="user-save">
						<i class="layui-icon layui-icon-ok"></i>
						提交
					</button>
					<button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
						<i class="layui-icon layui-icon-refresh"></i>
						重置
					</button>
				</div>
			</div>
		</form>
	</script>


	<!-- 依 赖 脚 本 -->
	{js href="/static/admin/component/layui/layui.js"}
	{js href="/static/admin/component/pear/pear.js"}
	<script>
		layui.use(['admin', 'jquery', 'form', 'popup'], function () {
			var admin = layui.admin;
			let $ = layui.jquery;
			let form = layui.form;
			let popup = layui.popup;
			admin.render({
				currentUser: "admin"
			});
			form.render()
			// 修改密码
			window.editPassword = function (obj) {
				layer.open({
					type: 1,
					title: '修改密码',
					shade: 0.1,
					area: ['320px', '320px'],
					content: $("#edit-form").html(),
					success: function (layero, index) {
						form.render()
					}
				});
			}

			// 保存
			form.on('submit(user-save)', function (data) {
				// 实例化表单
				var info = new FormData();
				info.append('password_old', data.field.password_old);
				info.append('password', data.field.password);
				info.append('token', data.field.token);
				var aurl = "/api/v1/user/editinfo";
				$.ajax({
					url: aurl,
					type: "post",
					dataType: "json",
					contentType: 'application/x-www-form-urlencoded;charset=utf-8',
					data: info,
					contentType: false, //不设置内容类型
					processData: false, //不处理数据
					beforeSend: function () {},
					success: function (data) {
						if (data.code == 200) {
							popup.success(data.msg, function () {
								layer.closeAll();
								window.location = './';
							});
						} else {
							popup.warming(data.msg, function () {});
						}
					},
					error: function (XMLResponse) {
						//异常捕获
						// layer.msg(XMLResponse.responseText);
						popup.warming("网络异常", function () {});
					}
				});
				return false;
			});

		})
	</script>
</body>

</html>